﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="favicon.ico">


    <link th:href="@{/hplus/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/hplus/css/animate.min.css}" rel="stylesheet">
    <link th:href="@{/hplus/css/style.min.css}" rel="stylesheet">
    <link th:href="@{/Xadmin/lib/layui/css/layui.css}" rel="stylesheet"/>
    <script th:src="@{/Xadmin/lib/layui/layui.js}"></script>
    <script th:src="@{/Scripts/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/Xadmin/js/xadmin.js}"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" name="searContent" id="crReload" placeholder="请输入原料名"
                                   autocomplete="off" th:value="${session.username}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" id="btncrReload" onclick="SelectName()" data-type="reload">搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="supplierTable" lay-filter="supplierTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/html" id="barContract">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">入库</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">出库</a>
        <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        //根据名字搜索
        function SelectName() {
            layui.table.reload('supplierTable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    name: $("#crReload").val()
                }
            });
        }

        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#supplierTable'
                , url: '/api/RawHouse/get'
                , limit: 3
                , limits: [3, 5, 35]
                , title: '用户数据表'
                , cols: [
                    [
                        {field: 'id', title: '商品名', fixed: 'left', unresize: true}
                        , {field: 'kindid', title: '商品名', fixed: 'left', unresize: true}
                        , {field: 'name', title: '数量', sort: true}
                        , {field: 'prime_cost', title: '单位', sort: true}
                        , {field: 'unit', title: '单位', sort: true}
                        , { fixed: 'right', title: '操作', width: 180, toolbar: '#barContract' }
                    ]
                ]
                , page: true
            });
            //监听行工具事件
            table.on('tool(supplierTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    layer.open({
                        type: 2,
                        title: '入库',
                        fixed: false, //不固定
                        maxmin: true,
                        content: '/Warehouse/WareAdd',
                        area: [470 + 'px', 300 + 'px'],
                        success: function (layero, index) {
                            var iframe = window['layui-layer-iframe' + index];
                            //调用子页面的全局函数
                            iframe.child(data.rawid, data.Name, 'RawHouse');
                        }
                    });
                    //xadmin.open('查看', `/Sale/SaleRecordDetail/${data.id}`, 800, 700);
                } else if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '出库',
                        fixed: false, //不固定
                        maxmin: true,
                        content: '/Warehouse/WareLess',
                        area: [470 + 'px', 300 + 'px'],
                        success: function (layero, index) {
                            var iframe = window['layui-layer-iframe' + index];
                            //调用子页面的全局函数
                            iframe.child(data.rawid, data.Name, 'RawHouse', data.Num);
                        }
                    });
                }else if(obj.event=='del'){
                    layer.confirm('真的删除行么',
                        function (index) {
                            $.ajax({
                                url: `/api/RawHouse/delete?id=${data.id}`,
                                type: 'DELETE',
                                success: function (res) {
                                    console.log(res)
                                    if (res.code === 0) {
                                        layer.msg(res.msg);
                                        obj.del();
                                        layer.close(index);
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        });
                }
            });
        });
    </script>
</div>
</body>
</html>
